<template>
  <div>
    <c-related>
      <template v-slot:slot1="props">
        <div>
          <c-mobile-title v-if="props.type=='mobile'" title="个人中心"/>
          <div class="info-view">
            <div class="info-pic">
              <img :src="userInfo.userPhoto?data.userPhoto:require('@/assets/images/man.png')" alt="" class="info-avatar">
            </div>
            <div class="info-cont">
              <p class="info-username">{{userInfo.nickName}}</p>
              <p class="info-balance">
                账户余额：
                <span class="info-balance-count">{{userInfo.accountBalance}}</span>
                屋币
                <router-link to="/index/recharge">
                  <span class="info-recharge">立即充值</span>
                </router-link>
              </p>
            </div>
          </div>
        </div>
      </template>

      <template v-slot:slot2="props">
        <div class="shelf-view">
          <p class="shelf-title">
            <span class="title-left">我的书架</span>
            <!-- <router-link to="/index/user/favorites"> -->
            <a href="#/index/user/favorites">
              <span class="title-right">全部收藏 ></span>
            </a>
            <!-- </router-link> -->
          </p>
          <c-user-book-list v-if="props.type=='pc'" :bookList="bookShelf"/>
          <c-simple-show-book v-if="props.type=='mobile'" :bookList="bookShelf"/>
        </div>
      </template>

    </c-related>
  </div>
</template>

<script>
import cSimpleShowBook from '@/components/user/SimpleShowBook.vue';
import cUserBookList from '@/components/user/UserBookList.vue';
import cRelated from './related/UserInfo_related.vue';
import cMobileTitle from '@/components/user/MobileTitle.vue';


export default {
  components:{
    cSimpleShowBook,cUserBookList,cRelated,cMobileTitle
  },
  data(){
    return{
      userInfo:{},
      bookShelf:[]
    }
  },
  created(){
    this.getUserInfo();
    this.listBookShelf();
  },
  methods:{
    getUserInfo(){
      this.$http.postForm('/user/userInfo', null, res=>{
        this.userInfo = res;
        this.$cookies.set("nickname", res.nickName, 0);
      });
    },
    listBookShelf(){
      this.$http.postForm('/user/listBookShelfByPage', {limit:5}, res=>{
        this.bookShelf = res.list;
      });
    }
  }
}
</script>

<style lang='scss' scoped>
</style>